import { storeToRefs } from 'pinia';
import { useCityList } from '/@/stores/cityList';
import useCommonState from '/@/utils/pageState/commonState';
const storesCity = useCityList();
const { SITE_DE, SITE_GB, SITE_US } = useCommonState();
const { CN, GB, US, DE } = storeToRefs(storesCity);

export default function () {
	// 最大数量
	const MAX_LENGTH = 99999999;

	// 来源
	const IN_EFFECT = 1;
	const EXPIRED = 0;
	const TO_BE_EFFECTIVE = 2;
	const COUPON_STATUS_LIST = [
		{
			value: '',
			label: '全部',
		},
		{
			value: IN_EFFECT,
			label: '生效中',
		},
		{
			value: EXPIRED,
			label: '已过期',
		},
		{
			value: TO_BE_EFFECTIVE,
			label: '待生效',
		},
	];

	// 优惠券规则
	const FULL_MINUS = 2; // 满减
	const DISCOUNT = 1; // 折扣
	const COUPON_RULES_LIST = [
		{
			value: FULL_MINUS,
			label: '满减',
		},
		{
			value: DISCOUNT,
			label: '折扣',
		},
	];

	// 使用商品的选项
	const USE_GOODS_1 = 0;
	const USE_GOODS_2 = 1;
	const USE_GOODS_3 = 2;
	const USE_GOODS_4 = 3;
	const USE_GOODS_LIST = [
		{
			value: USE_GOODS_1,
			label: '全部商品',
		},
		{
			value: USE_GOODS_2,
			label: '选择分类',
		},
		{
			value: USE_GOODS_3,
			label: '搜索商品',
		},
		{
			value: USE_GOODS_4,
			label: '批量导入',
		},
	];

	// 获取生效状态文本
	const getCouponStatusText = (params) => {
		let text = '';
		switch (params) {
			case IN_EFFECT:
				text = '生效中';
				break;
			case EXPIRED:
				text = '已过期';
				break;
			case TO_BE_EFFECTIVE:
				text = '待生效';
				break;
			default:
				text = '';
				break;
		}
		return text;
	};

	// 返回站点的标识
	const returnPlatform = (params) => {
		let state = SITE_DE;
		switch (params) {
			case GB:
				state = SITE_GB;
				break;
			case US:
				state = SITE_US;
				break;
			case DE:
				state = SITE_DE;
				break;
			default:
				state = SITE_DE;
				break;
		}
		return state;
	};

	// 根据站点返回对应的国家
	const returnCountryByPlatform = (params) => {
		let state = '';
		switch (params) {
			case SITE_GB:
				state = GB;
				break;
			case SITE_US:
				state = US;
				break;
			case SITE_DE:
				state = DE;
				break;
			default:
				state = '';
				break;
		}
		return state;
	};

	// 获取优惠券文本
	const getCouponRulesText = (params) => {
		let text = '';
		switch (params) {
			case FULL_MINUS:
				text = '满减';
				break;
			case DISCOUNT:
				text = '折扣';
				break;
			default:
				text = '';
				break;
		}
		return text;
	};

	// 获取国家货币字符
	const getCurrencySymbolText = (params) => {
		let text = '';
		switch (params) {
			case CN:
				text = '￥';
				break;
			case GB:
				text = '￡';
				break;
			case US:
				text = '$';
				break;
			case DE:
				text = '€';
				break;
			default:
				text = '';
				break;
		}
		return text;
	};

	// 获取国家货币字符
	const getCurrencySymbolTextBySite = (params) => {
		let platform = returnCountryByPlatform(params);
		let text = '';
		text = getCurrencySymbolText(platform);
		return text;
	};

	// 根据字段返回不同的价格文本
	const getPriceByField = (params, completeString, cuttingStrig = 'Price') => {
		let text = '';
		let cutString = completeString.split(cuttingStrig) ? completeString.split(cuttingStrig)[0] : '';
		// 这里拿到的cutString为eu，uk，us
		switch (cutString) {
			case 'eu':
				text = getCurrencySymbolText(DE);
				break;
			case 'uk':
				text = getCurrencySymbolText(GB);
				break;
			case 'us':
				text = getCurrencySymbolText(US);
				break;

			default:
				text = '';
				break;
		}
		return params ? text + params : text + '0';
	};

	// 根据优惠券类型返回不同的折扣/优惠金额
	const getPreferentialamount = (rule, params) => {
		let text = '';
		switch (rule) {
			case DISCOUNT:
				text = (params ? params : `0`) + '折';
				break;
			case FULL_MINUS:
				text = '减' + (params ? params : `0`);
				break;
			default:
				text = '';
				break;
		}
		return text;
	};
	return {
		MAX_LENGTH,
		IN_EFFECT,
		EXPIRED,
		TO_BE_EFFECTIVE,
		COUPON_STATUS_LIST,
		FULL_MINUS,
		DISCOUNT,
		COUPON_RULES_LIST,
		USE_GOODS_1,
		USE_GOODS_2,
		USE_GOODS_3,
		USE_GOODS_4,
		USE_GOODS_LIST,
		getCouponRulesText,
		getCurrencySymbolTextBySite,
		getCouponStatusText,
		returnPlatform,
		returnCountryByPlatform,
		getPriceByField,
		getPreferentialamount,
	};
}
